<template>
  <el-dialog title="请选择芯房" :visible.sync="dialogFormVisible" width="30%">
    <vab-query-form>
      <el-form
        ref="form"
        :model="queryForm"
        :inline="true"
        @submit.native.prevent
      >
        <!-- <el-form-item>
          <el-input
            v-model.trim="queryForm.queryBean.floorName"
            placeholder="楼盘名称"
            clearable
          />
        </el-form-item>
        <el-form-item>
          <el-button
            icon="el-icon-search"
            type="primary"
            native-type="submit"
            @click="handleQuery"
          >
            查询
          </el-button>
        </el-form-item> -->
      </el-form>
    </vab-query-form>
    <el-table
      ref="tableSort"
      v-loading="listLoading"
      :data="list"
      :element-loading-text="elementLoadingText"
      :height="height"
    >
      <el-table-column
        show-overflow-tooltip
        prop="projectName"
        label="项目名称"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="estateType"
        label="户型"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="status"
        label="状态"
      ></el-table-column>
      <el-table-column
        show-overflow-tooltip
        prop="price"
        label="价格"
      ></el-table-column>
      <el-table-column show-overflow-tooltip label="选择">
        <template #default="{ row }">
          <el-button
            type="primary"
            icon="el-icon-connection"
            @click="handleSelect(row)"
          ></el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :background="background"
      :current-page="queryForm.pageNum"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    ></el-pagination>
  </el-dialog>
</template>

<script>
  import { getAllHouse } from '@/api/building'
  import { parseTime } from '@/utils/index'
  import _ from 'lodash'
  export default {
    name: 'SelectEstate',
    data() {
      return {
        tempData: {},
        list: [],
        listLoading: false,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        background: true,
        elementLoadingText: '正在加载...',
        dialogFormVisible: false,
        queryForm: {
          pageNum: 1,
          pageSize: 10,
          queryBean: {},
        },
      }
    },
    computed: {
      height() {
        return this.$baseTableHeight()
      },
    },
    created() {},
    methods: {
      handleSelect(row) {
        let _data = {
          type: 'estate',
        }
        _data.id = row.businessEstateId
        _data.image = row.image
        _data.tempData = this.tempData
        this.$emit('setAd', _data)
        this.dialogFormVisible = false
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNum = val
        this.fetchData()
      },
      handleQuery() {
        this.queryForm.pageNum = 1
        if (this.queryBean.floorName == '') {
          this.queryForm.queryBean = {}
        } else {
          this.queryForm.queryBean = this.queryBean
        }
        this.fetchData()
      },
      showEdit(_data) {
        this.fetchData()
        this.tempData = _data
        this.dialogFormVisible = true
      },
      async fetchData() {
        this.listLoading = true
        // const
        const { data } = await getAllHouse(this.queryForm)
        const { body, message } = data
        if (message == '成功') {
          // const { data, totalSize } = body
          // this.total = totalSize
          this.list = body
          this.$baseNotify('数据获取完毕！', '成功', 'success', 'top-right')
          console.log(data)
        }
        this.listLoading = false
      },
      close() {
        this.dialogFormVisible = false
        // console.log(this.form.realEstateReview)
        this.$emit('fetch-data')
      },
      async confirm(value) {
        let _form = this.form.realEstateReview
        _form.evaluate = this.textarea
        _form.userId = this.form.userInfo.userId
        _form.reviewStatus = value ? 3 : 2
        const time = new Date()
        _form.reviewTime = parseTime(time)
        const { data } = await reviewRealEstate(_form)
        console.log(data)
        if (data.status === 0) {
          this.dialogFormVisible = false
          this.setStatus.realEstateReview.reviewStatus = 2
          this.$emit('fetch-data')
        } else {
          this.setStatus.realEstateReview.reviewStatus = 3
          if (value) {
            this.$emit('fetch-data')
            this.dialogFormVisible = false
          } else {
            this.$baseMessage(data.message, 'error')
          }
        }
      },
    },
  }
</script>
